home *** CD-ROM | disk | FTP | other *** search
- Path: sundog.tiac.net!smayo
- From: smayo@tiac.net (Scott Mayo)
- Newsgroups: comp.lang.c++
- Subject: Painted into a corner?
- Date: Thu, 01 Feb 1996 02:13:55 -0500
- Organization: The Internet Access Company
- Message-ID: <d5e2.smail.smayo@tiac.net>
- NNTP-Posting-Host: sunspot.tiac.net
-
- I've stumbled into an awkward case while setting up a few classes with
- multiple inheritance, and I'm not sure how to strauighten it out. Advice
- appreciated.
-
- I have a class, X, which is never going to be instantiated, but subclasses derived
- from it will be. I have another class, Y, which might be instantiated someday,
- though at the moment it exists only to support the subclasses Y1, Y2, and Y3.
-
- I need to create 3 new classes, X1, X2, and X3, which inherit as follows
- X1: X and Y1
- X2: X and Y2
- X3: X and Y3
- X4: X
-
- Very simple. It also turns out that I always need to manipulate instances of
- Xn through pointers to X, and trust to virtual functions
- to get the properly X1ish, X2ish and X3ish behaviour I need as regards
- the behaviour of the Yish parts. X4 is willing to support dummy functions
- so that it looks Yish as well; I'd rather it didn't inherit Y directly
- as that would make it pointlessly bulky.
-
- The problem, which the experienced folk here probably see already, is that
- if I create X *x, any time I try to do something like x->member_of_y(),
- I get told that member_of_y() isn't part of X. Well, no, of course it
- is not. I can't convince the compiler that any use of X* is going to refer
- to Xn, all of which will have some flavor of member_of_y().
-
- The closest I've come to a workaround is to create, in X,
- virtual member_of_y(), and then in each of X1...
-
- X1's member_of_y() {Y1::member_of_y();}
- X2's member_of_y() {Y2::member_of_y();}
-
- This strikes me as incenstous. X know knows a lot more than it ought
- about this upcoming marriage to Y. What am I missing? It's not
- practical to change all X* pointers to Y*.
-